Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(resolver): ignore non-component XML files in project #1452

Merged
merged 4 commits into from
Nov 5, 2024

Conversation

cristiand391
Copy link
Member

@cristiand391 cristiand391 commented Nov 1, 2024

What does this PR do?

Updates the metadata resolver to ignore XML files in a project that aren't part of a source component.

A customer had datapacks with an XML file that isn't part of the metadata inside force_app, when SDR built the component to deploy a specific metadata it would try to resolve the XML file as emailservicesfunction because the helpers to detect if a filepath was a metadata type were checking if the file suffix matched one in the registry (emailservicesfunction.suffix === 'xml').

This PR updates isMetadata to first try to find the type based on the suffix, if it there's not then it will check for strictDirectoryNames type ones and their directoryName.

Repro:

  1. create an invalid file in the project dir (force-app/main/default/lala/hehe.xml)
  2. update forceignore to ignore the file (/lala/)
  3. confirm it shows up when running sf project list ignored
  4. try deploying something via --metadata: sf project deploy start -m ApexClass
  5. see error about SDR trying to resolve an it as emailservicesfunction
  6. rename the file extension from file created in step one to something else other than xml, then step 4 works b/c it doesn't try to resolve it as a component.

What issues does this PR fix or reference?

@W-17113942@

@cristiand391 cristiand391 changed the title fix: resolver respects forceignore fix(resolver): ignore non-component XML files in project Nov 4, 2024
@cristiand391 cristiand391 marked this pull request as ready for review November 4, 2024 21:23
@cristiand391 cristiand391 requested a review from a team as a code owner November 4, 2024 21:23
if (!suffixType) return false;

const matchesSuffixType = fsPath.split(sep).includes(suffixType.directoryName);
if (matchesSuffixType) return matchesSuffixType;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for an XML file, suffixType would return the emailservicesfunction entry:

"xml": "emailservicesfunction",

// it might be a type that requires strict parent folder name.
const strictFolderSuffixType = registry
.getStrictFolderTypes()
.find((l) => l.suffix === suffixType.suffix && l.directoryName && l.name !== suffixType.name);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if registry.getTypeBySuffix entry didn't match, check for strictFolderTypes.

snapshot tests caught an issue with CustomSite where getTypeBySuffix would return sitedotcom (no match with the directoryName), this will return the strict folder types -> find if one with directoryName and suffix matches (and isn't suffixType).

@shetzel
Copy link
Contributor

shetzel commented Nov 5, 2024

Manual tests with the changes passed. I added a UT that fails without the changes so if CI is green we can merge.

@shetzel shetzel merged commit 36ea522 into main Nov 5, 2024
49 checks passed
@shetzel shetzel deleted the cd/forceignore-resolver branch November 5, 2024 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants